#include <stdio.h>
#include <stdlib.h>

#include <winsock2.h>
#include <Ws2tcpip.h>


void main(){


	char *message;
	char *buffer = "";
	int iResult;

	WSADATA wsaData;
	WORD wVersionRequested = MAKEWORD( 2, 2 );
	int err = WSAStartup( wVersionRequested, &wsaData );

	SOCKET s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	struct addrinfo *info;
	int ok = getaddrinfo("www.bt.se","80",NULL,&info);

	if(ok != 0){
		WCHAR * error = gai_strerror(ok);
		printf("%s\n",error);
	} else {
		while(info->ai_family != AF_INET && info->ai_next != NULL){
			info = info->ai_next;
		}
	}

	ok = connect(s,info->ai_addr,info->ai_addrlen);

	message = "GET / HTTP/1.1\r\nHOST: www.bt.se\r\n\r\n";
	ok = send(s,message,strlen(message),0);

	if (ok == -1){
		WCHAR * error = gai_strerror(ok);
		printf("error: %s\n",error);
	}

	buffer = malloc(512);

	while ((iResult = recv(s, buffer, 512, 0)) > 0) {
		iResult = recv(s,buffer,512,0);
		buffer[iResult] = '\0';
		printf("%s\n", buffer);
	}

	WSACleanup();
}

